#!/usr/bin/env python
# -*- coding: utf-8 -*-
import time
import math
import hashlib
import random
import requests
def get_cook():
    t = int(math.floor(time.time()))
    e = hex(t).upper()[2:]
    m = hashlib.md5()
    m.update(str(t).encode(encoding='utf-8'))
    i = m.hexdigest().upper()
    if len(e) != 8:
        AS = '479BB4B7254C150'
        CP = '7E0AC8874BB0985'
        return AS,CP
    n = i[0:5]
    a = i[-5:]
    s = ''
    r = ''
    for o in range(5):
        s += n[o] + e[o]
        r += e[o + 3] + a[o]
    AS = 'A1' + s + e[-3:]
    CP = e[0:3] + r + 'E1'
    return AS,CP
def get_url(max_behot_time,cn,en):
    url = "https://www.toutiao.com/api/pc/feed/?category=news_hot&utm_source=toutiao&widen=1&max_behot_time={0}&tadrequire=true&as={1}&cp={2}".format(max_behot_time,cn,en)
    next_max_behot_time = requests.get(url,headers = {'user-agent':'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36'}).json()
    if next_max_behot_time['message'] == 'success':
        return next_max_behot_time['next']['max_behot_time']
if __name__ == '__main__':
    refresh = 101
    a = []
    headers = {
        'user-agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36'
    }
    cn, en = get_cook()
    max_behot_time = 0
    for x in range(0,refresh+1):
        if refresh:
            max_behot_time = get_url(max_behot_time,cn,en)